--[[
    @desc: 这是一个登陆面板
    author:{zcg}
    time:2019-07-19 24:50:23
    {paramdesc}
    @return:
]]
LoginPanel = {}
local this = LoginPanel

function LoginPanel:OnDestroy()
    EventDispatcher.Instance:RemoveAllEventListener(this)
    uiMgr:DestroyPlane(this.panel)
    LoginPanel = nil
end

function LoginPanel.Awake(go)
    this.gameObject = go
    this.transform = go.transform
    this.panel = tostring(PanelEnum.LoginPanel)
    print("awake" .. go.name)

    this.test = Test2
    this.test.a = 5
end

function LoginPanel.Start()
    UGUIEx.SetActive(uiMgr:GetGameObject(this.panel .. ".txtError"), false)
    BtnEx.SetBtnEvent(uiMgr:GetGameObject(this.panel .. ".btnLogin"), nil, WoogiUI.UIEventType.mouseClick, this.OnLogin)
    BtnEx.SetBtnEvent(uiMgr:GetGameObject(this.panel .. ".btnRegist"), nil, WoogiUI.UIEventType.mouseClick, this.OnRegist)
    TxtEx.OnValueChanged(uiMgr:GetObj(this.panel .. ".accout", "InputField"), this.OnInputChanged)
    TxtEx.OnValueChanged(uiMgr:GetObj(this.panel .. ".password", "InputField"), this.OnInputChanged)
    -- event
    EventDispatcher.Instance:AddEventListener(CommonEventType.Update, this, this.Update)
end

function LoginPanel.OnInputChanged(arg)
    UGUIEx.SetActive(uiMgr:GetGameObject(this.panel .. ".txtError"), false)
    TxtEx.SetValue(uiMgr:GetObj(this.panel .. ".txtError", "Text"), "")
end

function LoginPanel.Update()
    print(this.gameObject.name)
    --[[this.test.Test()
    Test2.Test()
    print(".............................")]]
end

function LoginPanel.OnLogin(go)
    local account = uiMgr:GetObj(this.panel .. ".accout", "InputField")
    if account ~= nil then
        if string.len(account.text) < 6 then
            UGUIEx.SetActive(uiMgr:GetGameObject(this.panel .. ".txtError"), true)
            TxtEx.SetValue(uiMgr:GetObj(this.panel .. ".txtError", "Text"), "用户名长度不能小于6个字符")
            return
        end
    end

    local password = uiMgr:GetObj(this.panel .. ".password", "InputField")
    if password ~= nil then
        if string.len(password.text) < 6 then
            UGUIEx.SetActive(uiMgr:GetGameObject(this.panel .. ".txtError"), true)
            TxtEx.SetValue(uiMgr:GetObj(this.panel .. ".txtError", "Text"), "密码长度不能小于6个字符")
            return
        end
    end
    this.OnInputChanged(nil)
    print(account.text .. "_" .. password.text)
    Demo.ResourceManager.LoadLevel("Game")
end

function LoginPanel.OnRegist(go)
    UGUIEx.SetActive(uiMgr:GetGameObject(this.panel .. ".txtError"), true)
    TxtEx.SetValue(uiMgr:GetObj(this.panel .. ".txtError", "Text"), "开发中....")
end
